<?php
/**
 * 网站后台统一入口
 * @var action
 */

// 定义一些常量
define ('DOMAIN', 'http://local.cms.com/my_cms/admin/');
define ('IMG_DOMAIN', 'http://img.1mobile.com/');

// APP_ROOT必须定义,并且必须定义为APP_ROOT
define ('APP_ROOT', dirname (__FILE__));
//加载mvc框架
require_once (APP_ROOT.'/../mvc/mymvc.php');

define ('MODEL_PATH', APP_ROOT . '/model/');
define ('CONTROL_PATH',APP_ROOT.'/control/');
define ('UPLOAD_PATH',APP_ROOT.'/upload/');

// 定义smarty的路径
define ('TEMPLATE_DIR', APP_ROOT . '/view/');
define ('COMPILE_DIR', APP_ROOT . '/view_c/');

// 加载项目的配置文件
C (require_once (APP_ROOT . '/config/config.php'));

require_once(CONTROL_PATH.'CommonControl.class.php');

session_start ();

// 传递过来的参数是xxx.xxx形式，如果没有.,控制器直接调用Index
$act = trim ($_GET["act"]);

if (empty ($_SESSION['user']) && (empty ($act) || $act != 'admin.doLogin')){
	$act = 'admin.login';
}elseif(empty($act)){
	$act = 'home.idx';
}

list ($controller, $action) = explode ('.', $act);
$controller = ucfirst (strtolower ($controller));

$controller = (!empty ($controller)) ? $controller : 'Admin'; // 获取控制器,默认index
$controller_name = $controller . 'Control';
$controller_file = APP_ROOT . '/control/' . $controller_name . '.class.php'; // 获取控制器文件

if (file_exists ($controller_file)){
	require_once ($controller_file);
	$controller = new $controller_name ();
	if (method_exists ($controller, $action . 'Action')){
		$controller->{$action . 'Action'} ();
	}else{
		exit('method not exists!');
	}
}else{
	exit('method not exists!');
}